wowwikifandomcom-20200223-history
Creating simple pop-up dialog boxes
This page is being edited. Introduction This HOWTO covers the creation of what Blizzard calls static popups. These are the simple one-button and two-button dialog boxes you see when confirming a warlock summon, sending money through the mail, renaming a pet, and so forth. As you might expect, all of the basic UI elements (positioning, sound effects, layout) are handled for you. If you are trying for more complicated dialog boxes, such as CT_RaidAssist's "ready check", then you are reading the wrong page. :-) Basic Setup The example on this page will assume that you have two functions, called GreetTheWorld and IgnoreTheWorld, and that you are creating a simple dialog to ask the player whether or not to be socially outgoing. All of our own addon's variable names will begin with EXAMPLE_. New dialogs are created by adding an entry to the global StaticPopupDialogs table, and populating the entry with required and optional information. Here is a simple two-button entry: StaticPopupDialogs"EXAMPLE_HELLOWORLD" = { text = "Do you want to greet the world today?", button1 = "Yes", button2 = "No", OnAccept = function() GreetTheWorld(); end, timeout = 0, whileDead = 1, hideOnEscape = 1 }; Here you see the basic required information, along with some settings that are strictly optional but should be given by all well-behaved entries: * text - This is the text inside the dialog box. For example, "Looting this item will bind it to you." * button1 - This is the text on the left "yes" button. Clicking this button will call the OnAccept function in the entry. In a popup with only one button, it is this one. Some dialogs (like the "you are not part of this instance's group and are going to get teleported" warning) do not even have a single button. * button2 - This is the text on the right "no" button. If the entry has an OnCancel function, clicking this button will call it with "clicked" as the reason. * OnAccept - This is a local function; it can be as complicated as you like. You do not need to explicitly hide the popup frame, it will be done for you. * timeout - After this many seconds, the dialog will go away. If the entry has an OnCancel function, it will be called with "timeout" as the reason. Dialogs which do not expire should set this to zero. * whileDead - Set to 1 if this dialog can be shown while the player is a ghost. You probably want to do this. * hideOnEscape - Set to 1 if hitting the Escape key should be treated like clicking button2. You probably want to do this. Displaying the Popup To display the dialog, call StaticPopup_Show with the name of the entry: StaticPopup_Show ("EXAMPLE_HELLOWORLD"); The dialog will be put together and displayed, and the function returns as soon as the dialog is shown. If all goes well, the XML frame object for that dialog will be returned from the function. If there are any problems, it returns nil. This function has two more optional arguments, see Dialog_Text_Parameters below. Advanced Setup * OnAccept - This function can take up to two arguments, both optional. They are for passing arbitrary data around the callbacks. There are very few examples of the use of the arguments. In general this is used with dialogs that have an editable text field, to pass the entered text back to the function. Also for chaining dialog boxes together. * OnCancel - This function can take up to two arguments, both optional. The first is used the same way as the first parameter in OnAccept (whatever that may actually be). The second is a string describing the reason the popup was cancelled; the game will pass this as required: ** "override" - Another popup cancelled this one, or is set to 'exclusive', or the player is dead or logging out. ** "timeout" - The popup's entry specified a nonzero timeout field, and the time expired. ** "clicked" - The player clicked button2, or hit the escape key and hideOnEscape is set. Dialog Text Parameters The text field of an entry can contain formatting placeholders. When the popup is actually displayed, the calling function can pass two additional arguments to StaticPopup_Show. The text field and these two arguments will be passed through the format function before being added to the dialog. For example, the default guild invitation popup sets text = "%s invites you to join %s", and the display call is to StaticPopup_Show ("GUILD_INVITE", name_of_officer, name_of_guild). Editable Text Fields complicated, do later pet renames, clicking on "add ignore" or "add raid member" or "create new chat window tab", etc Optional Features There are some more settings available for use in static popup entries. This list is almost certainly incomplete, I'm just describing the ones which catch my eye. For more information, extract the StaticPopup.xml and .lua files from the default UI and browse. * sound - Play this sound when the dialog is displayed. For example, "igPlayerInvite". * hasMoneyFrame - This is for things like the money-in-mail confirmation. See the LUA file for more. * showAlert - Set this to 1 if you also want the OH NO SOMETHING BAD icon to be displayed in the popup. For example, deleting a mail message with an item still attached to it. * notClosableByLogout - Normally if a player quits the game, your popup will go away and its OnCancel function will be called. Set this field to 1 to avoid that behavior. * cancels - If your popup should make another popup go away, set this field to that popup's name. For example, cancels = "EXAMPLE_HELLOWORLD". If that popup is displayed at the time yours is shown, that popup's OnCancel function will be called and its frame hidden. * StartDelay and delayText - These fields are responsible for things like the delay before you can resurrect, before you get kicked out of an ungrouped instance, etc. The first is a function (a pointer to the function itself, not its name) to be called which returns the number of seconds which must pass before button1 can be used. The second is text to be displayed during the delay; it is formatted like the normal text field, with the time as the parameters. * exclusive - Set this to 1 to make your popup go away if any other popup is displayed. Notes and Observations * The 'text' fields and button1/2 fields are usually localized. Blizzard tends to use generic texts like ACCEPT, CANCEL, and OKAY; you can probably do the same. They wrap all those in a call to TEXT() for translation, like button1 = TEXT(ACCEPT) -Documentation by Farmbuyer Category: HOWTOs